import os
import asyncio
import logging
from openai import AsyncOpenAI
from agents import Agent, OpenAIChatCompletionsModel, Runner, function_tool, set_tracing_disabled

logging.basicConfig(level=logging.DEBUG)

BASE_URL = "https://api.siliconflow.cn/v1"
API_KEY = os.getenv("API_KEY", "sk-0d9449d2355a4c63******")
MODEL_NAME = "Qwen/Qwen3-8B"

if not BASE_URL or not API_KEY or not MODEL_NAME:
    raise ValueError(
        "Please set EXAMPLE_BASE_URL, EXAMPLE_API_KEY, EXAMPLE_MODEL_NAME via env var or code."
    )

client = AsyncOpenAI(base_url=BASE_URL, api_key=API_KEY)
set_tracing_disabled(disabled=True)

@function_tool
def get_weather(city: str):
    logging.info(f"[DEBUG] Getting weather for {city}")
    return f"{city}  的天气今天晴"

async def main():
    # 此代理将使用自定义的大模型LLM 
    agent = Agent(
        name="Assistant",
        instructions="你是一个助手，请使用工具来获取信息。",
        model=OpenAIChatCompletionsModel(model=MODEL_NAME, openai_client=client),
        tools=[get_weather],
    )

    result = await Runner.run(agent, "北京天气怎么样?")
    print(result.final_output)

if __name__ == "__main__":
    asyncio.run(main())
